Keywords
>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']
Definition
a keyword is a special word that is part of Python's syntax. They are not functions, methods, or objects. They define how the language is structured and executed.
| Category | Examples | Description |
|---|---|---|
| Control flow | if, elif, else, for, while, break, continue, return, yield | Manage loops and decision-making |
| Structure and definitions | def, class, lambda, with, as | Define functions, classes, and contexts |
| Logical and comparison | and, or, not, is, in | Combine or compare values |
| Exception handling | try, except, finally, raise, assert | Handle errors and enforce conditions |
| Import and namespace | import, from, global, nonlocal, del | Manage scope and module access |
| Special purpose | True, False, None, pass, await, async, match, case | Language-level constants or syntax keywords |